package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.dao.AdminDao;
import com.baizhi.cmfz.entity.Admin;
import com.baizhi.cmfz.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminDao adminDao;
    @Override
    public boolean login(String username, String password) {
        Admin admin= adminDao.showNameAndPwd(username);
        if(admin!=null && username!=null && password.equals(admin.getPassword())){
           return true;
        }
        return false;
    }

    @Override
    public Map showPageAdmin(int page, int limit) {
        int offset=(page-1)*limit;
        List<Admin> list=adminDao.showPageAdmin(offset,limit);
        int count=adminDao.showCount();
        Map map=new HashMap();
        if(count>0){
            map.put("data",list);
            map.put("count",count);
            map.put("code",0);
            map.put("msg","");
        }
        return map;
    }
}
